// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var startTime;
var EndTime;
var pcall_running = 0;
var tag_value = "";
var received = 1;
var tag_arr = new Array();
var limit_arr = new Array();

function addLimit(limit){
    limit_arr.push(limit)
}

function clearLimit(){
    limit_arr = new Array();
}


function clearTags(){
    tag_arr = new Array();
}

function addPeriodCall(){
    new PeriodicalExecuter(function() {
        if (pcall_running == 1&& received == 1){
            new Ajax.Updater('', 'home/period_call', {
                method: 'get',
                asynchronous: true,
                evalScripts: true,
                parameters: {
                    tag: tag_value
                }
            });
            tag_value = "";
        }
    }, 2)
}

function setTag(){
    temp = document.getElementById("tag_field").value;
    if(tag_arr.indexOf(temp)==-1){
        if(limit_arr.indexOf(temp)==-1){
            tag_value = temp;
            tag_arr.push(tag_value);
            document.getElementById("tags").innerHTML += "<br>"+tag_value;
        }
        else{
            document.getElementById("gameinfo").innerHTML = temp+" is banned.";
        }
    }
    document.getElementById("tag_field").value = "";
}

function initTime()
{
    startTime = new Date();
    EndTime=startTime.getTime()+120*1000;
}

function GetRTime(){
    var NowTime = new Date();
    var nMS =EndTime - NowTime.getTime();
    var nM=Math.floor(nMS/(1000*60)) % 60;
    var nS=Math.floor(nMS/1000) % 60;
    document.getElementById("RemainM").innerHTML=nM;
    document.getElementById("RemainS").innerHTML=nS;
    if(nMS <=0.3 )
    {
        document.getElementById("RemainM").innerHTML='0';
        document.getElementById("RemainS").innerHTML='0';
        document.getElementById('doover').click();
        return;
    }
    setTimeout("GetRTime()",1000);
}

function showTagInputArea(){
    document.getElementById('tag_input_area').style.display = "";
}

function hiddenStartButton(){
    document.getElementById('start_button').style.display = "none";
}
